//
//  SEProvineController.m
//  kuaiyi
//
//  Created by Alphts on 16/7/6.
//  Copyright © 2016年 Alphts. All rights reserved.
//

#import "SEProvineController.h"
#import "SEProvinceDTO.h"
#import "SECitiesController.h"
#import "SEWeatherDTO.h"
@interface SEProvineController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) NSArray <SEProvinceDTO *>*dataArray;

@end

@implementation SEProvineController




- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"provinceCell"];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
}

#pragma mark - 数据源和代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"provinceCell" forIndexPath:indexPath];
    
    cell.textLabel.text = self.dataArray[indexPath.row].name;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    SECitiesController *citiesVc = [[SECitiesController alloc] init];
    
    citiesVc.cities = self.dataArray[indexPath.row].cities;
    
    citiesVc.cityBlock = ^(SEWeatherDTO *model,NSString *cityName){
        
        if (self.cityBlock) {
            self.cityBlock(model,cityName);
        }
        
    };
    
    
    [self.navigationController pushViewController:citiesVc animated:YES];
    
}



#pragma mark - lazyload
- (NSArray<SEProvinceDTO *> *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [SEProvinceDTO provineArray];
    }
    return _dataArray;
}

@end













